﻿@page "/gestureplayground"

<ContentPage>
    <StackLayout Margin="new Thickness(20)">

        <Label Text="Tap me or pan me"
               FontSize="40" BackgroundColor="Color.LightCoral">
            <TapGestureRecognizer NumberOfTapsRequired="1" OnTapped="@OnLabelTapped" />
            <PanGestureRecognizer OnPanUpdated="@OnLabelPanned" />
        </Label>

        <Label Text="@($"The label above was clicked {count} times")" FontSize="@fontSize" BackgroundColor="Color.AliceBlue" />

        <Label Text="@($"Swipe left to delete, right to archive [STATE: {swipeState}]")" FontSize="40" BackgroundColor="Color.AntiqueWhite">
            <SwipeGestureRecognizer Direction="SwipeDirection.Left" OnSwiped="@OnSwipeLabel" />
            <SwipeGestureRecognizer Direction="SwipeDirection.Right" OnSwiped="@OnSwipeLabel" />
        </Label>

    </StackLayout>
</ContentPage>

@code
{
    int count;
    double fontSize = 20;
    string swipeState = "none";

    void OnLabelTapped()
    {
        count += 1;
        StateHasChanged();
    }

    void OnLabelPanned(PanUpdatedEventArgs e)
    {
        fontSize = 20 + e.TotalX;
        StateHasChanged();
    }

    void OnSwipeLabel(SwipedEventArgs e)
    {
        swipeState = e.Direction switch
        {
            SwipeDirection.Left => "deleted",
            SwipeDirection.Right => "archive",
            _ => "unknown: " + e.Direction.ToString(),
        };

        StateHasChanged();
    }
}
